﻿using System;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
    /// <summary>
    /// Specifies that name to use for the assembly being built.
    /// </summary>
    public class AssemblyBuilderNameAttribute : Attribute
    {
        private readonly string assemblyName;

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="AssemblyBuilderNameAttribute"/> class.
        /// </summary>
        /// <param name="assemblyName">Name of the assembly.</param>
        public AssemblyBuilderNameAttribute(string assemblyName)
        {
            this.assemblyName = assemblyName;
        }
        #endregion Constructors

        #region Public Properties
        /// <summary>
        /// Gets the name of the assembly.
        /// </summary>
        /// <value>The name of the assembly.</value>
        public string AssemblyName
        {
            get { return this.assemblyName; }
        }
        #endregion Public Properties

        #region Public Methods
        public static string GetAssemblyName(Type type)
        {
            var nameAttribute = (AssemblyBuilderNameAttribute)Attribute.GetCustomAttribute(
                type,
                typeof(AssemblyBuilderNameAttribute));

            return nameAttribute == null ? null : nameAttribute.AssemblyName;
        }
        #endregion Public Methods
    }
}